package com.itheima.config;

import com.itheima.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 配置拦截器
 * @Author: hsp
 * @Date: 2022/11/19-11-19-23:39
 * @Description: com.itheima.config
 * @version: 1.0.0
 */
@Configuration
public class ManagerConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    //设置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //定义放行路径
        List<String> urls = new ArrayList<>();

        urls.add("/**/*.js");
        urls.add("/**/*.css");
        urls.add("/**/*.jpg");
        urls.add("/**/*.png");
        urls.add("/**/*.html");
        urls.add("/admin/user/login");
        urls.add("/admin/user/logout");

        //配置拦截器和路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/admin/**")    // 拦截所有
                .excludePathPatterns(urls);    // 放行指定路径
    }

}
